package com.dingreading.cloud.mall.service.impl;

import com.dingreading.cloud.common.util.DateUtil;
import com.dingreading.cloud.mall.entity.NjTicketOrder;
import com.dingreading.cloud.mall.entity.table.NjTicketOrderTableDef;
import com.dingreading.cloud.mall.mapper.NjTicketOrderMapper;
import com.dingreading.cloud.mall.service.NjTicketOrderService;
import com.mybatisflex.core.query.QueryCondition;
import com.mybatisflex.core.update.UpdateChain;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 *  服务层实现。
 *
 * @author Administrator
 * @since 2024-12-23
 */
@Service
public class NjTicketOrderServiceImpl extends BaseServiceImpl<NjTicketOrderMapper, NjTicketOrder, NjTicketOrderTableDef> implements NjTicketOrderService {

    @Override
    protected NjTicketOrderTableDef getTable() {
        return NjTicketOrderTableDef.njTicketOrder;
    }

    @Override
    public NjTicketOrder getByCode(String code, String year) {
        return getMapper().selectOneByCondition(table.orderCode.eq(code).and(table.year.eq(year)));
    }

    @Override
    public boolean payOk(String code, String year, String tradeType, String buyerId, String tradeNo, String payTime, Date callBackTime) {
        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.orderCode.eq(code))
                .and(table.payStatus.eq(0))
                .and(table.year.eq(year));
        return UpdateChain.of(NjTicketOrder.class)
                .set(table.tradeType, tradeType)
                .set(table.payTime, payTime)
                .set(table.buyerId, buyerId)
                .set(table.tradeNo, tradeNo)
                .set(table.payStatus, 1)
                .set(table.payStatusName, "已支付")
                .set(table.payCallbackTime, callBackTime)
                .where(condition)
                .update();
    }
}
